<template>
  <view>
    <view
      class="registere_serve_box"
      v-for="(item, index) in serviceList"
      :key="item.id"
      @click="toDetails(item.id, index)"
    >
      <view class="registere_serve_image">
        <image :src="item.image != '[]' ? JSON.parse(item.image)[0].url : ''" mode="aspectFill"></image>
      </view>

      <view class="registere_serve_container">
        <view>
          <!-- <image :src="JSON.parse(item.pictures)[0].mainImage"/> -->
        </view>
        <view class="registere_serve_title">{{ item.serverName }}</view>
        <view class="registere_serve_description">{{ item.serverInstruction }}</view>
        <view class="registere_serve_price">
          <text>
            <text class="current_price">￥{{ Number(item.price).toFixed(2) }}</text>
            <!-- <text class="original_price">￥{{ Number(item.price) * 2 }}</text> -->
          </text>
          <text class="total_view">
            <u-icon name="eye" color="#B3B3B3" size="30"></u-icon>
            <text>{{ item.viewNumber }}</text>
          </text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    serviceList: {
      type: Array,
      default: () => [
        {
          category: {
            id: 5,
            category: '财税服务',
            parentId: 2,
            sort: 0,
            status: 0,
            createTime: null,
            updateTime: null,
            children: [],
            parentCategory: '服务分类',
          },
          id: 59,
          serverName: '服务名称14修改的',
          serverInstruction: '服务说明',
          categoryId: 5,
          recommend: 1,
          hot: 0,
          tag1: '无额度',
          tag2: '随便刷',
          price: 1.0,
          image:
            '[{"uid": "vc-upload-1599644610450-14", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/7d45d2d2c78e444eb92013e08c701a3bab72584e6bf86501dcbbb147c3d24a5.jpg"}]',
          detailImage:
            '[{"uid": "vc-upload-1599644247224-13", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/43e8e3838ef8452a8df474ccd83110610653a779106655e288e7c45a173dada.jpg"}]',
          mainImage:
            '[{"uid": "vc-upload-1599644247224-9", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/3d9e8cd41c744c9aaa8e15683bf8c35ea4d6de49ff39c5ed690cc4e8b807388.jpg", "index": 0}, {"uid": "vc-upload-1599644247224-11", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/6860b3bc3da9480784672f71a1cf41373177ea1ad2346fa9b17fb15d03056ca.jpg", "index": 1}, {"uid": "vc-upload-1599644247224-21", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/98af7e0c28d148dab633dff93b8d0a11a4d6de49ff39c5ed690cc4e8b807388.jpg", "index": 2}]',
          sales: 0,
          publishTime: null,
          status: 0,
          createTime: '2020-09-09 17:38:05',
          updateTime: '2020-09-09 19:00:51',
          viewNumber: 41,
          collectionNumber: null,
          linkServer: null,
        },
        {
          category: {
            id: 5,
            category: '财税服务',
            parentId: 2,
            sort: 0,
            status: 0,
            createTime: null,
            updateTime: null,
            children: [],
            parentCategory: '服务分类',
          },
          id: 58,
          serverName: '服务名称13修改的',
          serverInstruction: '服务说明',
          categoryId: 5,
          recommend: 1,
          hot: 0,
          tag1: '无额度',
          tag2: '随便刷',
          price: 1.0,
          image:
            '[{"uid": "vc-upload-1599644610450-14", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/7d45d2d2c78e444eb92013e08c701a3bab72584e6bf86501dcbbb147c3d24a5.jpg"}]',
          detailImage:
            '[{"uid": "vc-upload-1599644247224-13", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/43e8e3838ef8452a8df474ccd83110610653a779106655e288e7c45a173dada.jpg"}]',
          mainImage:
            '[{"uid": "vc-upload-1599644247224-9", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/3d9e8cd41c744c9aaa8e15683bf8c35ea4d6de49ff39c5ed690cc4e8b807388.jpg", "index": 0}, {"uid": "vc-upload-1599644247224-11", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/6860b3bc3da9480784672f71a1cf41373177ea1ad2346fa9b17fb15d03056ca.jpg", "index": 1}, {"uid": "vc-upload-1599644247224-21", "url": "https://eqiatong-public.oss-cn-beijing.aliyuncs.com/2020-09/09/98af7e0c28d148dab633dff93b8d0a11a4d6de49ff39c5ed690cc4e8b807388.jpg", "index": 2}]',
          sales: 0,
          publishTime: null,
          status: 1,
          createTime: '2020-09-09 17:38:05',
          updateTime: '2020-09-09 19:24:56',
          viewNumber: 14,
          collectionNumber: null,
          linkServer: null,
        },
      ],
    },
  },
  data() {
    return {
      myId: '',
    }
  },

  methods: {
    toDetails(value, index) {
      this.serviceList[index].viewNumber++
      uni.navigateTo({
        url: '../../pageTwo/productDetails/index?id=' + value,
      })
      // 浏览量+1
     // this.countView(value)
    },
    countView(value) {
      this.myId = uni.getStorageSync('userId') ? uni.getStorageSync('userId') : ''
      this.$http
        .post('/api/serverInc', {
          userId: this.myId,
          serverId: value,
        })
        .then((res) => {
          console.log('res', res.data.data)
        })
    },
  },
}
</script>

<style lang="scss" scoped>
@import './index.scss';
</style>
